<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>首页</title>
    <base href="${ pageContext.servletContext.contextPath }/">
    <link rel="icon" href="statics/img/favicon.svg" sizes="any" type="image/svg+xml">
    <link rel="stylesheet" href="statics/css/base.css">
    <link rel="stylesheet" href="statics/css/index.css">
</head>
<body>
	<c:if test="${ empty page }">
	<jsp:forward page="book/list?no=${ param.no }&size=5"></jsp:forward>
	</c:if>
    <%@include file="/pages/common/header.jsp" %>
    
    <!-- 主体 -->
    <main>
        <div class="top">
        	<form action="${ page.url }">
        		价格：<input type="number" name="min" value="${ param.min }" defaultValue="0" min="0"> 元 -
        		<input type="number" name="max" value="${ param.max }" defaultValue="0" min="0"> 元
        		<button>查询</button>
        		<button><a href="${ pageContext.servletContext.contextPath }">清空</a></button>
        	</form>
         	<p>
         		<c:if test="${ empty cart or cart.items.size() == 0 }">
         			您的购物车为空！
         		</c:if>
         		<c:if test="${ not empty cart and cart.items.size() != 0 }">
         			您的购物车中有<strong>${ empty cart || cart.totalCount == 0 ? 0 : cart.totalCount }</strong>件商品
         			<c:if test="${ not empty lastName }">
	         		您刚刚将<strong>${ lastName }</strong>加入到了购物车中
	         		</c:if>
         		</c:if>
         	</p>
        </div>
        <section class="book-list">
        	<c:if test="${ empty bookList }">
        	<p class="message">未查询到数据</p>
        	</c:if>
        	<c:if test="${ not empty bookList }">
        	<table>
	        	<thead>
	        		<tr>
		        		<th>ID</th>
		        		<th>图片</th>
		        		<th>书名</th>
		        		<th>作者</th>
		        		<th>价格</th>
		        		<th>销量</th>
		        		<th>库存</th>
		        		<th>操作</th>
		        	</tr>
	        	</thead>
	        	<tbody>
	        		<c:forEach items="${ bookList }" var="book">
	        		<tr>
			    		<th>${ book.id }</th>
						<td><img src="${ book.imgPath.indexOf('/upload') == 0 ? book.imgPath.substring(0) : book.imgPath }"></td>
						<td>${ book.name }</td>
						<td>${ book.author }</td>
						<td>${ book.price }</td>
						<td>${ book.sales }</td>
						<td>${ book.stock }</td>
						<td>
							<form action="cart/add" method="POST">
								<input type="hidden" name="id" value="${ book.id }" />
								<button>加入购物车</button>
							</form>
						</td>
					</tr>
					</c:forEach>
	        	</tbody>
	        </table>
	        </c:if>
        </section>
        <c:if test="${ not empty bookList }">
        <%@include file="/pages/common/pagination.jsp" %>
        </c:if>
    </main>
    <%@include file="/pages/common/footer.jsp" %>
    
    <script src="statics/js/index.js"></script>
</body>
</html>